package cn.stronglink.assetmanage.business.task;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;

import java.util.List;

import cn.stronglink.assetmanage.BaseActivity;
import cn.stronglink.assetmanage.MyApplication;
import cn.stronglink.assetmanage.R;
import cn.stronglink.assetmanage.entity.Task;
import cn.stronglink.assetmanage.utils.dao.TaskDataUtil;

public class TaskActivity extends BaseActivity {
    TabLayout tbTask;
    ViewPager vpTask;
    private TaskViewPagerAdapter mAdapter;
    private FragmentManager fm;
    private String[] mTaskTitle = MyApplication.APP_CONTEXT.getResources().
            getStringArray(R.array.task);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_task);
        initView();
        initData();
    }


    private void initView() {
        tbTask = findViewById(R.id.tl_task);
        vpTask = findViewById(R.id.vp_task);
    }

    private void initData() {
        fm = getSupportFragmentManager();
        List<Task> mFinishTaskList = TaskDataUtil.getFinishTaskNoDistance();
        List<Task> mUnFinishTaskList = TaskDataUtil.getUnfinishTaskNoDisntance();
        int finishSize = mFinishTaskList.size();
        int unfinishSize = mUnFinishTaskList.size();
        mTaskTitle = new String[]{"待处理(" + unfinishSize + ")",
                "已完成(" + finishSize + ")"};
        mAdapter = new TaskViewPagerAdapter(fm,mTaskTitle);
        vpTask.setAdapter(mAdapter);
        tbTask.setupWithViewPager(vpTask);
        tbTask.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vpTask.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    protected void onResume() {
        super.onResume();
        initData();
    }


    @Override
    public void onBackPressed() {

    }

}
